load("//proto:compiler.bzl", "go_proto_compiler")
load("//proto:gogo.bzl", "gogo_special_proto")
load("//proto/wkt:well_known_types.bzl", "GOGO_WELL_KNOWN_TYPE_REMAPS", "WELL_KNOWN_TYPE_RULES")

go_proto_compiler(
    name = "go_proto_bootstrap",
    visibility = ["//visibility:public"],
    deps = [
        "@com_github_golang_protobuf//proto:go_default_library",
    ],
)

go_proto_compiler(
    name = "go_proto",
    visibility = ["//visibility:public"],
    deps = [
        "@com_github_golang_protobuf//proto:go_default_library",
    ] + WELL_KNOWN_TYPE_RULES.values(),
)

go_proto_compiler(
    name = "go_grpc",
    options = ["plugins=grpc"],
    visibility = ["//visibility:public"],
    deps = [
        "@com_github_golang_protobuf//proto:go_default_library",
        "@org_golang_google_grpc//:go_default_library",
        "@org_golang_x_net//context:go_default_library",
    ] + WELL_KNOWN_TYPE_RULES.values(),
)

go_proto_compiler(
    name = "go_proto_validate",
    plugin = "@com_github_mwitkow_go_proto_validators//protoc-gen-govalidators",
    suffix = ".validator.pb.go",
    valid_archive = False,
    visibility = ["//visibility:public"],
    deps = [
        "@com_github_golang_protobuf//proto:go_default_library",
    ],
)

GOGO_VARIANTS = [
    "combo",
    "gogo",
    "gogofast",
    "gogofaster",
    "gogoslick",
    "gogotypes",
    "gostring",
]

[go_proto_compiler(
    name = variant + "_proto",
    options = GOGO_WELL_KNOWN_TYPE_REMAPS,
    plugin = "@com_github_gogo_protobuf//protoc-gen-" + variant,
    visibility = ["//visibility:public"],
    deps = [
        "@com_github_gogo_protobuf//gogoproto:go_default_library",
        "@com_github_gogo_protobuf//proto:go_default_library",
        "@com_github_gogo_protobuf//sortkeys:go_default_library",
        "@com_github_gogo_protobuf//types:go_default_library",
    ] + WELL_KNOWN_TYPE_RULES.values(),
) for variant in GOGO_VARIANTS]

go_proto_compiler(
    name = "gofast_proto",
    plugin = "@com_github_gogo_protobuf//protoc-gen-gofast",
    visibility = ["//visibility:public"],
    deps = [
        "@com_github_golang_protobuf//proto:go_default_library",
    ] + WELL_KNOWN_TYPE_RULES.values(),
)

[go_proto_compiler(
    name = variant + "_grpc",
    options = ["plugins=grpc"] + GOGO_WELL_KNOWN_TYPE_REMAPS,
    plugin = "@com_github_gogo_protobuf//protoc-gen-" + variant,
    visibility = ["//visibility:public"],
    deps = [
        "@com_github_gogo_protobuf//gogoproto:go_default_library",
        "@com_github_gogo_protobuf//proto:go_default_library",
        "@com_github_gogo_protobuf//sortkeys:go_default_library",
        "@com_github_gogo_protobuf//types:go_default_library",
        "@org_golang_google_grpc//:go_default_library",
        "@org_golang_x_net//context:go_default_library",
    ] + WELL_KNOWN_TYPE_RULES.values(),
) for variant in GOGO_VARIANTS]

go_proto_compiler(
    name = "gofast_grpc",
    options = ["plugins=grpc"],
    plugin = "@com_github_gogo_protobuf//protoc-gen-gofast",
    visibility = ["//visibility:public"],
    deps = [
        "@com_github_golang_protobuf//proto:go_default_library",
        "@org_golang_google_grpc//:go_default_library",
        "@org_golang_x_net//context:go_default_library",
    ] + WELL_KNOWN_TYPE_RULES.values(),
)

filegroup(
    name = "all_rules",
    testonly = True,
    srcs = glob(["*.bzl"]) + ["//proto/wkt:all_rules"],
    visibility = ["//:__subpackages__"],
)
